//
//  QLMBXOrderDetailVC.m
//  Xiaomakuaixiu
//
//  Created by 龚碧容 on 2017/10/11.
//  Copyright © 2017年 hwd. All rights reserved.
//

#import "QLMBXOrderDetailVC.h"
#import "QLMTopDetailTVCell.h"
#import "QLMMidDetailTVCell.h"
#import "QLMBottomDetailTVCell.h"
#import "QLMServiceManDetailVC.h"
#import "IQKeyboardManager.h"

#import "QLMPhotoInfoTabCell.h"
#import "QLMEvaluationVC.h"

#import "QLBxOrderCostVC.h"
#import "QLMOrderSerManModel.h"
#import "QLMEvaluInfoModel.h"
#import <UMSocialCore/UMSocialCore.h>
#import <UShareUI/UShareUI.h>

@interface QLMBXOrderDetailVC ()<UITableViewDataSource,UITableViewDelegate,QLMPhotoInfoTabCellDelegate>{
    NSArray *tipsArray;
    NSMutableArray *selectedPhotos;
    
    QLMMidDetailTVCell *midcell;
    QLMBottomDetailTVCell *bottomcell;
    NSString *maintenanceEvaluation;
    NSDictionary *maintenanceEvaluationDic;
    NSDictionary *aEvaluationDic;
    NSInteger isClassInt;
    QLMOrderSerManModel *orderSerManModel;
    NSString *customerEvaluationNumber;
    
    QLMEvaluInfoModel *evaluInfoModel;
    UITableView *_otableview;
}
@property (nonatomic,assign)BOOL isPush;
@end

@implementation QLMBXOrderDetailVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title=@"报修详情";

    isClassInt=0;
    aEvaluationDic=[NSDictionary dictionary];
    maintenanceEvaluationDic=[NSDictionary dictionary];
    
    selectedPhotos=[NSMutableArray array];

    tipsArray=[NSArray arrayWithObjects:@"基本信息",@"联系信息",@"故障详情", nil];
    CGRect rect=CGRectMake(0, 0, kScreen_width, kScreen_height-IOS11_OR_LATER_SPACE(34)-QLM_StatusBarAndNavigationBarHeight);
    _otableview=[[UITableView alloc] initWithFrame:rect style:UITableViewStylePlain];
    _otableview.backgroundColor=[UIColor clearColor];
    _otableview.delegate=self;
    _otableview.dataSource=self;
    _otableview.separatorStyle=UITableViewCellSeparatorStyleNone;
    _otableview.showsVerticalScrollIndicator=NO;
    _otableview.showsHorizontalScrollIndicator=NO;
    _otableview.tableFooterView=[UIView new];
    [self.view addSubview:_otableview];

    //下拉刷新
    _otableview.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(requRepairOrder)];
    _otableview.mj_header.automaticallyChangeAlpha = YES;
    
    _isPush=YES;
    
//    [self setupRightNavigationBar];
    
//    [[NSNotificationCenter defaultCenter] addObserver:self
//                                             selector:@selector(getScreenshot:)
//                                                 name:UIApplicationUserDidTakeScreenshotNotification object:nil];
}

//- (void)setupRightNavigationBar{
//    UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
//    rightButton.frame = CGRectMake(0, 0, 44, 44);
//    [rightButton setImage:[UIImage imageNamed:@"04_new"] forState:UIControlStateNormal];
//    [rightButton setBackgroundColor:[UIColor clearColor]];
//    rightButton.contentHorizontalAlignment=UIControlContentHorizontalAlignmentCenter;
//    [rightButton addTarget:self action:@selector(showBottomNormalView) forControlEvents:UIControlEventTouchUpInside];
//
//    UIBarButtonItem *fixedSpace = [[UIBarButtonItem alloc]
//                                   initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
//                                   target:nil
//                                   action:nil];
//    fixedSpace.width = 0;
//    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithCustomView:rightButton];
//    self.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects:rightItem,fixedSpace,nil];
//}


#pragma mark - share
//- (void)showBottomNormalView{
//    [UMSocialShareUIConfig shareInstance].sharePageGroupViewConfig.sharePageGroupViewPostionType = UMSocialSharePageGroupViewPositionType_Bottom;
//
//    [UMSocialShareUIConfig shareInstance].sharePageScrollViewConfig.shareScrollViewPageItemStyleType = UMSocialPlatformItemViewBackgroudType_IconAndBGRoundAndSuperRadius;
//
//    [UMSocialUIManager showShareMenuViewInWindowWithPlatformSelectionBlock:^(UMSocialPlatformType platformType, NSDictionary *userInfo) {
//        [self shareImageURLToPlatformType:platformType];
//    }];
//}

//分享网络图片
//- (void)shareImageURLToPlatformType:(UMSocialPlatformType)platformType{
//    UIImage *thmimage = [UIImage imageWithData:[self imageDataScreenShot]];
//    UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
//
//    UMShareImageObject *shareObject = [[UMShareImageObject alloc] init];
//    shareObject.thumbImage=nil;
//    shareObject.shareImage=thmimage;
//
//    messageObject.shareObject = shareObject;
//
//    //调用分享接口
//    [[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:messageObject currentViewController:self completion:^(id data, NSError *error) {
//        if (error) {
//            UMSocialLogInfo(@"Share fail with error %@",error);
//        }else{
//            if ([data isKindOfClass:[UMSocialShareResponse class]]) {
//                UMSocialShareResponse *resp = data;
//                UMSocialLogInfo(@"response message is %@",resp.message);
//                UMSocialLogInfo(@"response originalResponse data is %@",resp.originalResponse);
//            }else{
//                UMSocialLogInfo(@"response data is %@",data);
//            }
//        }
//        [self alertWithError:error];
//    }];
//}
//
//- (void)alertWithError:(NSError *)error{
//    NSString *result = nil;
//    if (!error) {
//        result = [NSString stringWithFormat:@"分享成功"];
//    }else{
//        NSMutableString *str = [NSMutableString string];
//        if (error.userInfo) {
//            for (NSString *key in error.userInfo) {
//                [str appendFormat:@"%@ = %@\n", key, error.userInfo[key]];
//            }
//        }
//        if (error) {
//            result = [NSString stringWithFormat:@"分享失败错误信息: %d\n%@",(int)error.code, str];
//        }else{
//            result = [NSString stringWithFormat:@"分享失败"];
//        }
//    }
//    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"分享"
//                                                    message:result
//                                                   delegate:nil
//                                          cancelButtonTitle:@"确定"
//                                          otherButtonTitles:nil];
//    [alert show];
//}

//- (void)getScreenshot:(NSNotification *)notification{
//    NSLog(@"捕捉截屏事件");
//    //获取截屏图片
//    UIImage *image = [UIImage imageWithData:[self imageDataScreenShot]];
//    //显示图片
//    UIImageView *imgV = [[UIImageView alloc]initWithImage:image];
//    imgV.frame = [UIScreen mainScreen].bounds;
//
//    UIView *backView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
//    backView.backgroundColor = [[UIColor grayColor] colorWithAlphaComponent:0.8];
//
//    UIButton *shareBtn = [UIButton buttonWithType:UIButtonTypeSystem];
//    shareBtn.titleLabel.font = [UIFont systemFontOfSize:17.0];
//    [shareBtn setTintColor:[UIColor whiteColor]];
//    shareBtn.frame = CGRectMake(SCREEN_WIDTH/5,SCREEN_HEIGHT ,SCREEN_WIDTH*3/5,50);
//    [shareBtn.layer setMasksToBounds:YES];
//    [shareBtn.layer setBorderWidth:1];
//    shareBtn.layer.cornerRadius = 6;
//    [shareBtn setTitle:@"分享给好友" forState:UIControlStateNormal];
//    shareBtn.backgroundColor = [UIColor redColor];
//    [shareBtn addTarget:self action:@selector(shareBtn:) forControlEvents:UIControlEventTouchUpInside];
//
//    [backView addSubview:imgV];
//    [backView addSubview:shareBtn];
//
//    UIWindow *window = [UIApplication sharedApplication].keyWindow;
//    [window addSubview:backView];
//
//    [UIView animateWithDuration:1.0 animations:^{
//        imgV.transform = CGAffineTransformMakeScale(0.8, 0.8);
//        shareBtn.transform = CGAffineTransformMakeTranslation(0, -50);
//    }];
//    //3秒后消失
//    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(8 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
//        [backView removeFromSuperview];
//    });
//}

//- (NSData *)imageDataScreenShot{
//    CGSize imageSize = CGSizeZero;
//    imageSize = [UIScreen mainScreen].bounds.size;
//
//    UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0);
//    CGContextRef context = UIGraphicsGetCurrentContext();
//    for (UIWindow *window in [[UIApplication sharedApplication] windows]){
//        CGContextSaveGState(context);
//        CGContextTranslateCTM(context, window.center.x, window.center.y);
//        CGContextConcatCTM(context, window.transform);
//        CGContextTranslateCTM(context, -window.bounds.size.width * window.layer.anchorPoint.x, -window.bounds.size.height * window.layer.anchorPoint.y);
//        if ([window respondsToSelector:@selector(drawViewHierarchyInRect:afterScreenUpdates:)]){
//            [window drawViewHierarchyInRect:window.bounds afterScreenUpdates:YES];
//        }else{
//            [window.layer renderInContext:context];
//        }
//        CGContextRestoreGState(context);
//    }
//
//    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
//    UIGraphicsEndImageContext();
//
//    return UIImagePNGRepresentation(image);
//}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden=NO;

    self.tabBarController.tabBar.hidden = YES;
    
    IQKeyboardManager *keyboardManager = [IQKeyboardManager sharedManager];
    keyboardManager.enable = NO; // 控制整个功能是否启用

    [self _setUpSelectPhoto];
    
    if (!_isPush) {
        [self requRepairOrder];
    }else{
        if ([ClientTool isNull:_resultInfoModel.receiverMaintenanceId]){
            [self requestOrderListData];
            [self requestEvalutionData];
        }
    }
        
    if (_isBXAddJumpBool) {
        ETToastWithDelay(@"报修订单创建成功，服务工程师稍后会联系您，谢谢！",3);
    }
}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    
    if (_isBXAddJumpBool) {
        self.tabBarController.tabBar.hidden = NO;
    }
    IQKeyboardManager *keyboardManager = [IQKeyboardManager sharedManager];
    keyboardManager.enable = YES;
    
    _isPush=NO;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - 返回按钮
- (void)leftClick{
    if (_isBXAddJumpBool) {
        [self.navigationController popToRootViewControllerAnimated:YES];
    }else{
        if (_isPushJumpBool) {
            [self.navigationController popToRootViewControllerAnimated:YES];
        }else{
            [self.navigationController popViewControllerAnimated:YES];
        }
    }
}

#pragma mark -
- (NSString *)resultString:(NSString *)classificationId{
    NSString *classificationStr=nil;
    switch ([classificationId integerValue]) {
        case 0:
            classificationStr=@"发动机";
            break;
        case 1:
            classificationStr=@"电气";
            break;
        case 2:
            classificationStr=@"液压";
            break;
        case 3:
            classificationStr=@"其他";
            break;
        case 4:
            classificationStr=@"保养";
            break;
        default:
            break;
    }
    return classificationStr;
}

- (NSString *)resultStatus:(NSString *)resultStr{
    NSString *orderStatusStr=nil;
    switch ([resultStr integerValue]) {
        case 0:
            orderStatusStr=@"待派工";
            break;
        case 1:
            orderStatusStr=@"已派工";
            break;
        case 2:
            orderStatusStr=@"已预约";
            break;
        case 3:
            orderStatusStr=@"已出发";
            break;
        case 4:
            orderStatusStr=@"已到达";
            break;
        case 5:{
            
            if ([_resultInfoModel.erpOrderStatus integerValue]==0) {
                orderStatusStr=@"待支付(服务结束)";
            }else if ([_resultInfoModel.erpOrderStatus integerValue]==1){
                orderStatusStr=@"支付中";
            }else if ([_resultInfoModel.erpOrderStatus integerValue]==2){
                orderStatusStr=@"已评价";
                if ([self isEvalutionBool]==NO) {
                    orderStatusStr=@"待评价";
                }
            }else if ([_resultInfoModel.erpOrderStatus integerValue]==3){
                orderStatusStr=@"支付失败";
            }else{
                orderStatusStr=@"已结束";
            }
            
        }
            break;
        case 6:
            orderStatusStr=@"已中断";
            break;
        case 7:
            orderStatusStr=@"中断出发";
            break;
        default:
            break;
    }
    return orderStatusStr;
}

- (BOOL)isNull:(id)object{
    // 判断是否为空串
    if ([object isEqual:[NSNull null]]) {
        return NO;
    }else if ([object isKindOfClass:[NSNull class]]){
        return NO;
    }else if (object==nil){
        return NO;
    }
    return YES;
}

- (BOOL)isEvalutionBool{
    
    if (isClassInt==0){
        return NO;
    }else if (isClassInt==1) {
        if (![self isNull:maintenanceEvaluation]) {
            return NO;
        }
    }else if (isClassInt==2) {
        if (nil==maintenanceEvaluationDic[@"customerEvaluationNumber"]) {
            return NO;
        }
    }
    return YES;
}

- (void)_setUpSelectPhoto{
    [selectedPhotos removeAllObjects];
    if (self.resultInfoModel.pictureDetail.count!=0) {
        for (QLMpictureDetailModel *picDetailModel in self.resultInfoModel.pictureDetail) {
            NSString *ulrStr=[NSString stringWithFormat:@"%@%@",kBaseURL,picDetailModel.pathName];
            NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:ulrStr]];
            UIImage *aimage = [UIImage imageWithData:data];
            if (aimage!=nil) {
                [selectedPhotos addObject:aimage];
            }
        }
    }
}

#pragma mark - request data
- (void)requRepairOrder{
    NSMutableDictionary *paramerDic=[NSMutableDictionary dictionary];
    [paramerDic setObject:_repairOrderId forKey:@"repairOrderId"];
    
    [self.view makeToastActivity:CSToastPositionCenter];
    [ClientTool postUrlPath:@"/test/repairOrder/orderInfo" withParamers:paramerDic andBody:nil
                    success:^(id responseObject){
                        NSInteger code = [[responseObject objectForKey:@"flag"] integerValue];
                        if (code == 1) {
                            _resultInfoModel=[[QLMOrderListInfoModel alloc] initWithDictionary:responseObject[@"repairOrder"] error:nil];
                            if ([ClientTool isNull:_resultInfoModel.receiverMaintenanceId]){
                                [self requestOrderListData];
                                [self requestEvalutionData];
                            }
                            [self _setUpSelectPhoto];
                            [_otableview reloadData];
                        }else{
                            ETToast(responseObject[@"msg"]);
                        }
                        [_otableview.mj_header endRefreshing];
                        [self.view hideToastActivity];
                    }failure:^(NSError *error){
                        ETToast(@"服务器连接失败");
                        [_otableview.mj_header endRefreshing];
                        [self.view hideToastActivity];
                    }
     ];
}

- (void)requestOrderListData{
    NSMutableDictionary *paramerDic=[NSMutableDictionary dictionary];
    [paramerDic setObject:_resultInfoModel.repairOrderId forKey:@"repairOrderId"];
    [self.view makeToastActivity:CSToastPositionCenter];
    [ClientTool postUrlPath:@"/rest/maintenance/getByrepairOrderId" withParamers:paramerDic andBody:nil
                    success:^(id responseObject){
                        [self.view hideToastActivity];
                        NSInteger code = [[responseObject objectForKey:@"flag"] integerValue];
                        if (code == 1) {
                            
                            if (![[responseObject[@"maintenanceEvaluation"] class] isSubclassOfClass:[NSDictionary class]]) {
                                isClassInt=1;
                                maintenanceEvaluation=responseObject[@"maintenanceEvaluation"];
                            }else{
                                isClassInt=2;
                                maintenanceEvaluationDic=responseObject[@"maintenanceEvaluation"];
                                evaluInfoModel=[[QLMEvaluInfoModel alloc] initWithDictionary:maintenanceEvaluationDic error:nil];
                            }
                            [_otableview reloadData];
                        }else{
                            ETToast(responseObject[@"msg"]);
                        }
                    }failure:^(NSError *error){
                        [self.view hideToastActivity];
                        ETToast(@"服务器连接失败");
                    }
     ];
}

- (void)requestEvalutionData{
    NSMutableDictionary *paramerDic=[NSMutableDictionary dictionary];
    [paramerDic setObject:_resultInfoModel.receiverMaintenanceId forKey:@"id"];
    [paramerDic setObject:_resultInfoModel.erpOrderNo forKey:@"orderNo"];
    
    [self.view makeToastActivity:CSToastPositionCenter];
    [ClientTool postUrlPath:@"/rest/serviceEvaluation/getById" withParamers:paramerDic andBody:nil
                    success:^(id responseObject){
                        [self.view hideToastActivity];
                        NSInteger code = [[responseObject objectForKey:@"flag"] integerValue];
                        if (code == 1) {
                            aEvaluationDic=responseObject[@"data"];
                            orderSerManModel=[[QLMOrderSerManModel alloc] initWithDictionary:aEvaluationDic[@"obj"] error:nil];
                            customerEvaluationNumber=[aEvaluationDic[@"maintenanceEvaluation"] objectForKey:@"customerEvaluationNumber"];
                        }else{
                            ETToast(responseObject[@"msg"]);
                        }
                    }failure:^(NSError *error){
                        [self.view hideToastActivity];
                        ETToast(@"服务器连接失败");
                    }
     ];
}

#pragma mark - Action
- (void)checkServiceManAction:(UIButton *)sender{
    
    if (sender.tag==1040) {
        if (![self isNull:_resultInfoModel.receiverMaintenanceId]) {
            ETToast(@"该订单没有服务人员接单，请稍后重试");
            return;
        }
        QLMEvaluationVC *evaluationVC=[QLMEvaluationVC new];
        evaluationVC.orderListInfoModel=_resultInfoModel;
        evaluationVC.evaluInfoModel=evaluInfoModel;
        if ([self isEvalutionBool]==NO) {
            evaluationVC.canEditeBool=YES;
        }else{
            evaluationVC.canEditeBool=NO;
        }
        evaluationVC.serviceStart=orderSerManModel.servicerLevelNum;
        self.hidesBottomBarWhenPushed=YES;
        [self.navigationController pushViewController:evaluationVC animated:YES];
        
    }else if(sender.tag==1041){
        QLBxOrderCostVC *bxOrderCostVC=[QLBxOrderCostVC new];
        bxOrderCostVC.orderListInfoModel=_resultInfoModel;
        self.hidesBottomBarWhenPushed=YES;
        [self.navigationController pushViewController:bxOrderCostVC animated:YES];
    }else{
        
        QLMServiceManDetailVC *servicemanVC=[QLMServiceManDetailVC new];
        
        servicemanVC.receiverMaintenanceId=_resultInfoModel.receiverMaintenanceId;
        servicemanVC.erpOrderId=_resultInfoModel.erpOrderId;
        
        servicemanVC.addressDetail=_resultInfoModel.repairAddress;
        servicemanVC.repairLatitude=_resultInfoModel.repairLatitude;
        servicemanVC.repairLongitude=_resultInfoModel.repairLongitude;
        
        servicemanVC.orderStatus=_resultInfoModel.orderStatus;
        servicemanVC.orderSerManModel=orderSerManModel;
        servicemanVC.customerEvaluationNumber=customerEvaluationNumber;
        
        self.hidesBottomBarWhenPushed=YES;
        [self.navigationController pushViewController:servicemanVC animated:YES];
    }
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
- (CGFloat)calucationHeight:(NSIndexPath *)indexPath{
    if (indexPath.section==0) {
        if ([ClientTool isNull:_resultInfoModel.classificationId]) {
            return 140+25;
        }
        return 90;
    }else if (indexPath.section==1) {
        return 100;
    }else if (indexPath.section==2) {
        return 100;
    }
    if (selectedPhotos.count==0) {
        return 34;
    }
    return 130;
}

#pragma mark - UITableView datasource
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section==3) {
        return 0.1;
    }
    return 34;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *headerView=[[UIView alloc] init];
    headerView.backgroundColor=[UIColor whiteColor];
    
    if (section!=3) {
        UIButton *newButton = [UIButton buttonWithType:UIButtonTypeCustom];
        newButton.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft;
        newButton.frame = CGRectMake(15, 5, 100, 24);
        [newButton setImage:[UIImage imageNamed:@"icon"] forState:UIControlStateNormal];
        [newButton setTitle:tipsArray[section] forState:UIControlStateNormal];
        [newButton setTitleColor:UIColorFromRGB(0x333333) forState:UIControlStateNormal];
        newButton.titleLabel.font=[UIFont systemFontOfSize:18.0f];
        newButton.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0);
        newButton.titleEdgeInsets = UIEdgeInsetsMake(0, 6, 0, 0);
        [headerView addSubview:newButton];
    }

    return headerView;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    if (section==3) {
        if ([_resultInfoModel.orderStatus integerValue]<3) {
            return 0.1;
        }
        return 55;
    }
    if (section==2) {
        return 0;
    }
    
    return 10;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *footerView=[[UIView alloc] init];
    footerView.backgroundColor=[UIColor clearColor];
    footerView.userInteractionEnabled=YES;
    
    if (section==3) {
        footerView.backgroundColor=[UIColor whiteColor];
        NSString *btnTitle=@"查看维修人员";
        UIButton *newButton = [UIButton buttonWithType:UIButtonTypeCustom];
        newButton.contentHorizontalAlignment=UIControlContentHorizontalAlignmentCenter;
        newButton.frame = CGRectMake(0, 10, kScreen_width, 40);
        [newButton setTitle:btnTitle forState:UIControlStateNormal];
        [newButton setTitleColor:UIColorFromRGB(0xffffff) forState:UIControlStateNormal];
        newButton.titleLabel.font=[UIFont boldSystemFontOfSize:14.0f];
        newButton.backgroundColor=kButtonColor;
        [newButton addTarget:self action:@selector(checkServiceManAction:) forControlEvents:UIControlEventTouchUpInside];
        if ([_resultInfoModel.orderStatus integerValue]==3||[_resultInfoModel.orderStatus integerValue]==4) {
            if ([_resultInfoModel.erpOrderStatus integerValue]!=2){
                [footerView addSubview:newButton];
            }
        }
        for (int i=0; i<2; i++) {
            
            NSString *evaluStr=@"查看评价";
            if ([self isEvalutionBool]==NO) {
                evaluStr=@"去评价";
            }
            
            NSArray *btnTitleArr=[NSArray arrayWithObjects:evaluStr,@"查看订单费用详情",nil];
            
            UIButton *showButton = [UIButton buttonWithType:UIButtonTypeCustom];
            showButton.contentHorizontalAlignment=UIControlContentHorizontalAlignmentCenter;
            showButton.frame = CGRectMake(20+(kScreen_width/2-10)*i, 10, kScreen_width/2-30, 40);
            [showButton setTitleColor:UIColorFromRGB(0xffffff) forState:UIControlStateNormal];
            showButton.titleLabel.font=[UIFont boldSystemFontOfSize:14.0f];
            showButton.backgroundColor=kButtonColor;
            showButton.tag=1040+i;
            [showButton addTarget:self action:@selector(checkServiceManAction:) forControlEvents:UIControlEventTouchUpInside];
            
            if ([_resultInfoModel.erpOrderStatus integerValue]==2){//已支付状态显示查看费用按钮；-1为默认状态只有服务端app提交配件费用后才能改变状态为0， 0:未支付，1:支付中，2:支付成功,3:支付失败
                [showButton setTitle:btnTitleArr[i] forState:UIControlStateNormal];
                [footerView addSubview:showButton];
            }else{
                if (i==1) {
                    if ([_resultInfoModel.orderStatus integerValue]==5) {
                    
                        if ([_resultInfoModel.erpOrderStatus integerValue]!=-1){
                            showButton.frame = CGRectMake(20, 10, kScreen_width-40, 40);
                            [showButton setTitle:@"去支付" forState:UIControlStateNormal];
                            [footerView addSubview:showButton];
                        }
                    }
                }
            }
        }
    }
    
    return footerView;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 4;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section==0) {
        if ([ClientTool isNull:_resultInfoModel.classificationId]) {
            return 180;
        }
        return 90;
    }else if (indexPath.section==1) {
        return [midcell autoChangeHeightWithLabel:midcell.deviceaddressLa]+65+5;
    }else if (indexPath.section==2) {
        return [bottomcell autoChangeHeightWithLabel:bottomcell.decriptionLa]+10+5;
    }
    if (selectedPhotos.count==0) {
        return 34;
    }
    return 130;
}

- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return [self calucationHeight:indexPath];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section==0) {
        QLMTopDetailTVCell *topcell=[QLMTopDetailTVCell cellWithTableView:tableView];
        topcell.selectionStyle=UITableViewCellSelectionStyleNone;
        
        QLMequipManagerModel *equipManagerModel=self.resultInfoModel.equipmentManager;
        topcell.deviceNameLa.text=[NSString stringWithFormat:@"%@%@",equipManagerModel.brandName,equipManagerModel.modelName];
        
        NSString *serialNo=nil;
        if (equipManagerModel.serialNo.length==0) {
            serialNo=@"无";
        }else{
            serialNo=equipManagerModel.serialNo;
        }
        topcell.devicetypeLa.text=[NSString stringWithFormat:@"%@",serialNo];
        
        if (equipManagerModel.alias.length==0) {
            topcell.otherNameLab.text=@"无";
        }else{
            topcell.otherNameLab.text=equipManagerModel.alias;
        }

        topcell.orderNoLab.text=[NSString stringWithFormat:@"%@",_resultInfoModel.erpOrderNo];
        topcell.statusLa.textColor=kNavigationBarColor;
        topcell.statusLa.text= [self resultStatus:_resultInfoModel.orderStatus];
        topcell.deviceTroubleLa.text=[self resultString:_resultInfoModel.classificationId];
        
        return topcell;
        
    }else if(indexPath.section==1){
        midcell=[QLMMidDetailTVCell cellWithTableView:tableView];
        midcell.selectionStyle=UITableViewCellSelectionStyleNone;
        midcell.deviceaddressLa.text= self.resultInfoModel.repairAddress;
        midcell.deviceAddrNameLa.text= self.resultInfoModel.contactName;
        midcell.phoneLa.text= self.resultInfoModel.contactPhone;
        return midcell;
    }else if(indexPath.section==2){
        bottomcell=[QLMBottomDetailTVCell cellWithTableView:tableView];
        bottomcell.selectionStyle=UITableViewCellSelectionStyleNone;
        bottomcell.decriptionLa.text= self.resultInfoModel.statusStatement;
        return bottomcell;
    }
    
    QLMPhotoInfoTabCell *photocell=[QLMPhotoInfoTabCell cellWithTableView:tableView];
    photocell.delegate=self;
    photocell.isCanEditable=NO;
    photocell.selectedPhotos=selectedPhotos;
    
    if (selectedPhotos.count==0) {
        UILabel *_tiplabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 0, kScreen_width-100-20,34)];
        _tiplabel.text = @"无";
        _tiplabel.textColor=[UIColor darkGrayColor];
        _tiplabel.backgroundColor=[UIColor clearColor];
        _tiplabel.font = [UIFont systemFontOfSize:16];
        _tiplabel.textAlignment = NSTextAlignmentLeft;
        [photocell addSubview:_tiplabel];
    }
    
    photocell.selectionStyle=UITableViewCellSelectionStyleNone;
    return photocell;
}

#pragma mark - UITableView delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

- (void)tapPreViewerAction:(NSInteger)itemTag{//预览照片
    [XLPhotoBrowser showPhotoBrowserWithImages:selectedPhotos currentImageIndex:itemTag];
}

@end
